#!/bin/sh

BASEDIR="`dirname "${0}"`/.."
. "${BASEDIR}/functions"

TS_LOGFILE="startstop.rlog"

__beforeexit_cleanup()
{
  if [ ! -z "${TMP_PIDFILE}" ]
  then
    rtpproxy_stop TERM
  fi
  if [ -f "${TMP_LOGFILE}" ]
  then
    cat "${TMP_LOGFILE}" >> "${TS_LOGFILE}"
    rm "${TMP_LOGFILE}"
  fi
}

do_run()
{
  for bad_rargs in ${1}
  do
    IFS=\&
    set -o noglob
    RTPP_ARGS=`eval "echo \"${bad_rargs}\""`
    rtpproxy_start ${RTPP_ARGS}
    reportifnotfail "`basename ${RTPPROXY}` don't start with bad argumens: \""${RTPP_ARGS}"\""
    cat "${TMP_LOGFILE}" >> "${TS_LOGFILE}"
    rm "${TMP_LOGFILE}"
  done
}

RTPP_OUTFILE="startstop.rout"

truncate -s 0 "${TS_LOGFILE}"

myuid="`id -un`"
mygid="`id -gn`"

for rtpv in debug nodebug
do
  . ${BASEDIR}/startstop/badargs.${rtpv}.sub
  bad_rargs_all=`cat ${BA_ADD} ${BASEDIR}/startstop/badargs.common.input`
  do_run "${bad_rargs_all}" &
  DR_PID=${!}
  wait ${DR_PID}
  report "checks for `basename ${RTPPROXY}`"
done
